<template>
  <div>
    <h1>宝宝成长推荐</h1>
    <el-select v-model="selectedAge" placeholder="选择宝宝年龄阶段" @change="fetchBabyRecommendations">
      <el-option label="新生儿" value="newborn"></el-option>
      <el-option label="婴儿期" value="infant"></el-option>
      <el-option label="幼儿期" value="toddler"></el-option>
    </el-select>
    <el-table :data="babyRecommendations" style="width: 100%">
      <el-table-column prop="productName" label="商品名称"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button @click="viewProduct(scope.row.productId)">查看</el-button>
          <el-button @click="addToCart(scope.row.productId)">加入购物车</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getBabyGrowthRecommendations } from '@/api/recommendation';

export default {
  data() {
    return {
      babyRecommendations: [],
      selectedAge: '',
    };
  },
  methods: {
    async fetchBabyRecommendations() {
      const response = await getBabyGrowthRecommendations(this.selectedAge);
      this.babyRecommendations = response.data;
    },
    viewProduct(productId) {
      this.$router.push({ path: `/products/${productId}` });
    },
    addToCart(productId) {
      // 添加到购物车逻辑
    },
  },
};
</script>

<style scoped>
.baby-recommendations {
  padding: 20px;
}
</style> 